package com.thesis.manage.controller;

import com.thesis.manage.common.controller.AbstractController;
import com.thesis.manage.service.TeacherService;
import com.thesis.manage.service.model.RoleEnum;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @author php
 * @date 2018/1/29
 */
@RequestMapping("/teacher")
@RestController
public class TeacherController extends AbstractController {
    @Resource
    private TeacherService teacherService;

    @GetMapping("/list")
    public Map<String, Object> list(final Pageable pageable) {
        return buildMessage(() -> teacherService.detail(pageable));
    }

    /**
     * 导入数据
     *
     * @param file 数据文件
     */
    @PostMapping("/import")
    public Map<String, Object> importExcel(final MultipartFile file) {
        return buildMessage(() -> {
            teacherService.importExcel(file);
            return null;
        });
    }

    /**
     * 授权
     *
     * @param id 用户id
     */
    @PostMapping("/authorization")
    public Map<String, Object> authorization(final Long id, final Integer isAuth) {
        return buildMessage(() -> {
            teacherService.authorization(id, isAuth, RoleEnum.LEADER.getValue().longValue());
            return null;
        });
    }


    /**
     * 通过主键删除
     *
     * @param id id
     * @return map
     */
    @DeleteMapping("/{id}")
    public Map<String, Object> delete(final @PathVariable Long id) {
        return buildMessage(() -> {
            teacherService.delete(id);
            return null;
        });
    }

}
